export default {
    namespace: 'timeArea',
    state: {
        collapsed: [],
    },
    reducers: {
        save(state, { payload }) {
            return Object.assign({}, state, payload);
        }
    },
    effects: {
        *changeCollapsed({ payload }, { select, put }) {
            const timeArea = yield select(state => state.timeArea);
            const identifier = payload.identifier;
            let collapsed = timeArea.collapsed;
            collapsed.map((item, index) => {
                if (index !== identifier) {
                    collapsed[index] = true;
                }
            });
            if (typeof collapsed[identifier] !== 'boolean') {
                collapsed[identifier] = false;
            }
            else {
                collapsed[identifier] = !collapsed[identifier];
            }
            yield put({
                type: 'save',
                payload: {
                    collapsed
                }
            });
        },
    },
    subscriptions: {
        setup({ dispatch }) {
        }
    },
};
